package com.study.collection.HashSet;

import java.util.HashSet;
import java.util.Set;
import java.util.UUID;

/**
 * @ClassName HashSetErrorDemo
 * @Author: jianghaok
 * @Description  HashSet集合线程不安全案例展示
 * @Date: 2022/5/10
 * @Version 1.0
 */

// HashSet集合线程不安全案例展示
public class HashSetErrorDemo {
    public static void main(String[] args) {
        //演示Hashset
        Set<String> set = new HashSet<>();

        for (int i = 0; i < 30; i++) {
            new Thread(() -> {
                //向集合添加内容
                set.add(UUID.randomUUID().toString().substring(0, 8));
                //从集合获取内容
                System.out.println(set);
            }, String.valueOf(i)).start();
        }
    }
}
